package ali

var PayTpl = `
package aliyun

import (
    "context"
    "fmt"
    "{{.App}}/pkg/storage/conf"
    "github.com/google/uuid"
    "github.com/go-pay/gopay"
    "github.com/go-pay/gopay/alipay"
    "github.com/go-pay/xlog"
)

func AliYun() string {
    client, err := alipay.NewClient(conf.Cfg.Ali.AppId, conf.Cfg.Ali.PrivateKey, false)
    if err != nil {
        xlog.Error(err)
        return ""
    }
    client.SetCharset("utf-8").SetSignType(alipay.RSA2).SetNotifyUrl(conf.Cfg.Ali.NotifyUrl).SetReturnUrl(conf.Cfg.Ali.ReturnUrl)

    bm := make(gopay.BodyMap)
    bm.Set("subject", "标题")
    bm.Set("out_trade_no", uuid.NewString())
    bm.Set("total_amount", "88.88")
    bm.Set("product_code", "code+code+code")
    payUrl, err := client.TradePagePay(context.Background(), bm)

    if err != nil {
        xlog.Error(err)
        return ""
    }

    return payUrl
}
`
